﻿using System.Collections.Generic;
using System.Linq;
using Algoritmia.DataStructures.Digraphs;

namespace Algoritmia.Problems.ConnectedComponents
{
    public interface IConnectedComponentsFinder<T>
    {
        IEnumerable<IEnumerable<T>> ConnectedComponents(IDigraph<T> g);
    }

    public static class ConnectedComponentsFindersExtensions
    {
        public static bool IsConnected<T>(this IConnectedComponentsFinder<T> connectedComponentsFinder, IDigraph<T> graph)
        {
            return connectedComponentsFinder.ConnectedComponents(graph).Count() == 1;
        }
    }
}
